package com.woniu.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.domain.Position;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import com.woniu.vo.PositionVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import com.woniu.vo.DataPie;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import com.woniu.vo.PositionDetailsVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zyy
 * @since 2021-03-05
 */
public interface PositionMapper extends BaseMapper<Position> {
    //展示职位
    @Select("SELECT tp.position_id,tp.tname,tp.description,tp.requirements,tp.lasalary,tp.address,tp.tel,tp.visit_count  FROM t_position tp WHERE hot!=\"非热点\" ")
    List<PositionVo> findallPosition();

    //根据公司id查询该公司下的所有职位
    @Select("SELECT p.* " +
            "FROM t_position AS p " +
            "WHERE p.position_id IN  " +
            "(SELECT up.pid " +
            "FROM t_user_position AS up " +
            "WHERE up.uid IN  " +
            "(SELECT uc.user_id " +
            "FROM t_user_company AS uc " +
            "WHERE uc.company_id=#{compId}))")
    public List<Position> queryPositionByCid(Integer compId);

//    职位详情页面数据



    @Select("SELECT " +
            "p.position_id AS positionId, c.`name` AS companyName,p.tname AS positionName, " +
            "p.salary AS salary,p.requirements AS requirements,u.username AS userName, " +
            "p.description AS description, c.introduce AS introduce,c.address AS address, " +
            "c.company_id AS companyId, c.visit_count AS companyVisitCount, p.visit_count AS positionVisitCount\n" +
            "FROM " +
            "t_user AS u " +
            "JOIN t_user_company AS uc ON uc.user_id = u.id " +
            "JOIN t_company AS c ON c.company_id=uc.company_id " +
            "JOIN t_user_position AS up ON up.uid = u.id " +
            "JOIN t_position AS p ON p.position_id = up.pid " +
            "WHERE p.position_id=#{positionId}")
    public PositionDetailsVo jobTitle(Integer positionId );


    @Select("select p.*\n" +
            "from t_position p\n" +
            "join t_user_position up \n" +
            "on p.position_id=up.pid\n" +
            "join t_user_company uc \n" +
            "on uc.user_id=up.uid\n" +
            "join t_company c \n" +
            "on c.company_id=uc.company_id\n" +
            "where c.company_id=#{id}")
    List<Position> lookPositionByCompanyId(Integer id);


//    modifyStatus 点击投递简历按钮


    @Insert("INSERT INTO  t_feedback ( position_id,user_id,`status`) VALUES(#{positionId},#{userId},\"待处理\")")
    public int modifyStatus(Integer positionId, Integer userId);





    @Select("select tp.position_id,tp.tname,tp.description,tp.requirements,tp.lasalary,tp.address,tp.tel,tp.visit_count  FROM t_position tp where tname like CONCAT('%',#{tname,jdbcType=VARCHAR},'%')&&hot!=\"非热点\" ")
    List<PositionVo> findPosition(@Param("tname")String tname);

    @Select("SELECT p.*  FROM t_position as p INNER JOIN t_user_position AS up " +
            "ON p.position_id=up.pid  " +
            "${ew.customSqlSegment}")
    IPage<Position> getPage(Page<Position> page, QueryWrapper<Position> ew);

    @Select("SELECT c.`status` FROM t_company AS c INNER JOIN " +
            "t_user_company AS up ON c.company_id=up.company_id " +
            "WHERE up.user_id=#{uid}")
    String selectStatus(Integer uid);
}

